#include "../ourhdr.h"

void pr_stdio(const char*, FILE*);

int main(void)
{
    FILE *fp;
    fputs("enter any character\n", stdout);
    if(getchar()==EOF)
    {
        err_sys("getchar error");
    }

    pr_stdio("stdin", stdin);
    pr_stdio("stdout", stdout);
    pr_stdio("stderr", stderr);

    if( (fp=fopen("motd", "r")) ==NULL)
    {
        err_sys("fopen erorr");
    }
    if(getc(fp)==EOF)
    {
        err_sys("getc error");
    }
    pr_stdio("/etc/motd", fp);
    exit(0);
}

void pr_stdio(const char* name, FILE* fp)
{
    printf("stream = %s,", name);
    /***
     * unix _flag
     * macbook _flages
     */
    if(fp-> _flags & _IONBF)
    {
        printf("unbuffered");   
    }
    else if(fp->_flags & _IOLBF)
    {
        printf("line buffered");
    }
    else
    {
        printf("fully buffered");
    }
    /***
     * unix bufsiz
     * makbook _blksize
     */
    printf(", buffer size = %d\n", fp->_blksize);
}